﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="IzvadakProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class IzvadakProviderBase : IzvadakProviderBaseCore
	{
	    ///<summary>
	    ///</summary>
	    ///<param name="transactionManager"></param>
	    ///<param name="IDs"></param>
	    ///<param name="start"></param>
	    ///<param name="pageLength"></param>
	    ///<param name="count"></param>
	    ///<returns></returns>
	    public abstract PretvoreneStavkeIzvatkaList GetStavkeBytblIzvodIDs(TransactionManager transactionManager,
	                                                                       String IDs, int start, int pageLength,
	                                                                       out int count);
            ///<summary>
            ///</summary>
            ///<param name="reader"></param>
            ///<param name="rows"></param>
            ///<param name="start"></param>
            ///<param name="pageLength"></param>
            ///<returns></returns>
            public static PretvoreneStavkeIzvatkaList FillStavke(IDataReader reader, PretvoreneStavkeIzvatkaList rows, int start, int pageLength)
        {
            for (int i = 0; i < start; i++)
            {
                if (!reader.Read())
                    return rows; // not enough rows, just return
            }
            for (int i = 0; i < pageLength; i++)
            {
                if (!reader.Read())
                    break; // we are done
                string key = null;

                PretvoreneStavkeIzvatka c = new PretvoreneStavkeIzvatka();

                c.Vlasnik = reader.IsDBNull(reader.GetOrdinal("Vlasnik")) ? null : (String)reader["Vlasnik"];
                c.Vlasnikziroracun = reader.IsDBNull(reader.GetOrdinal("Vlasnikziroracun")) ? null : (String)reader["Vlasnikziroracun"];
                c.BrojIzvatka = (Int32) reader["BrojIzvatka"];
                c.BrojZaReklamaciju = reader.IsDBNull(reader.GetOrdinal("BrojZaReklamaciju")) ? null : (String)reader["BrojZaReklamaciju"]; 
                c.DatumTransakcije = (DateTime) reader["DatumTransakcije"];
                c.Dug = (Decimal) reader["Dug"];
                c.Pot = (Decimal) reader["Pot"];
                c.Model = reader.IsDBNull(reader.GetOrdinal("Model")) ? null : (String)reader["Model"]; 
                c.Pozivnabr = reader.IsDBNull(reader.GetOrdinal("Pozivnabr")) ? null : (String)reader["Pozivnabr"];
                c.Opis = reader.IsDBNull(reader.GetOrdinal("Opis")) ? null : (String)reader["Opis"];
                c.Veznaoznaka = reader.IsDBNull(reader.GetOrdinal("VeznaOznaka")) ? null : (String)reader["VeznaOznaka"];
                c.VjerovnikDuznikNaziv = reader.IsDBNull(reader.GetOrdinal("VjerovnikDuznikNaziv")) ? null : (String)reader["VjerovnikDuznikNaziv"];
                c.VjerovnikDuznikZiroracun = reader.IsDBNull(reader.GetOrdinal("VjerovnikDuznikZiroracun")) ? null : (String)reader["VjerovnikDuznikZiroracun"];
                c.IDKlijent = reader.IsDBNull(reader.GetOrdinal("IDKlijent")) ? null : (int?)reader["IDKlijent"];
                c.RedBrStavke =(int)reader["RedBrStavke"];
                rows.Add(c);
            }
            return rows;
        }
	} // end class
} // end namespace
